<template>
  <el-card class="article-main" shadow="hover" @click="clickArticle">
    <template #header>
      <el-tag effect="dark" size="mini">{{ todo.categoryName }}</el-tag>
      {{ todo.title }}
    </template>
    <div class="tag" v-if="todo.isSpecial">荐</div>
    <div class="article-content">{{ todo.content }}</div>
    <div class="article-message">
      <span>{{ todo.time }}</span>
      <i class="el-icon-view"><span style="margin-left: 5px">{{ todo.view }}</span></i>
    </div>
  </el-card>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import {IArticle} from "@/interface/article";
import {useRouter} from "vue-router";

export default defineComponent({
  name: "Article",
  props: {
    todo: {
      type: Object as () => IArticle,
      require: true,
    }
  },
  setup(props) {
    const router = useRouter()
    const clickArticle = () => {
      if(props.todo) router.push({ path: '/article', query: { id: props.todo.id}})
    }
    return {
      clickArticle,
    }
  }
})
</script>

<style scoped>
.article-main {
  margin-bottom: 10px;
  position: relative;
}
.article-main:hover {
  cursor: pointer;
}
.tag {
  position: absolute;
  top: 0;
  right: 0;
  font-size: 8px;
  font-weight: 600;
  background-color: #4CD964;
  height: 18px;
  line-height: 18px;
  width: 300px;
  text-align: center;
  transform: translate(46%) rotate(45deg);
}
.article-message {
  color: #999;
  font-size: 13px;
  margin-top: 13px;
  line-height: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.article-content {
  max-height: 5.5rem;
  font-size: 1rem;
  overflow: hidden;
}
/deep/ .el-card__header {
  padding: 10px;
}
/deep/ .el-card__body {
  padding: 10px;
}
</style>
